"""
@Author    : ghenyar
@Time      : 2025/9/1 10:46
@File      : role_model
@Desc      : 角色管理
"""
from datetime import datetime
from sqlalchemy import BigInteger, String, Text, DateTime
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import func
from app.models import DatabaseModel, table_prefix


class RoleModel(DatabaseModel):
    __tablename__ = f"{table_prefix}roles"
    __table_args__ = {"comment": "角色管理表"}

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True, comment="角色ID")
    name: Mapped[str] = mapped_column(String(100), nullable=False, unique=True, comment="角色名称")
    desc: Mapped[str] = mapped_column(String(255), nullable=False, comment="角色描述")
    permissions: Mapped[str] = mapped_column(Text, nullable=False, comment="角色权限")
    created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, server_default=func.now(),
                                                 comment="创建时间")
    updated_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True, onupdate=func.now(),
                                                        comment="更新时间")
